//
//  XDNavigationController.swift
//  weibo
//
//  Created by lucy on 2016/10/22.
//  Copyright © 2016年 com.huashengHuaSheng. All rights reserved.
//

import UIKit

class XDNavigationController: UINavigationController,UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
    interactivePopGestureRecognizer?.delegate = self
        
    }
    
    
    @objc private func backClick(){
    
        popViewController(animated: true)
    
    }
    
    
    //MARK-重新父类的push方法
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        var title : String
        if childViewControllers.count>0{
            title = "返回"
            if childViewControllers.count == 1{
            
                title = childViewControllers.first?.title ?? ""

            }
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(setHighlightImgName: "navigationbar_back_withtext", title: title, target: self, action: #selector(backClick))

        
        }
        super.pushViewController(viewController, animated: animated)
        
        
    }
    
    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
        return childViewControllers.count != 1
    }
 

}
































